<!DOCTYPE html >
<html>
<head>
    <link rel="stylesheet" href="demos.css" type="text/css" media="screen" />
    
    <script type="text/javascript" src="../libraries/RGraph.common.core.js" ></script>
    <script type="text/javascript" src="../libraries/RGraph.common.dynamic.js" ></script>
    <script type="text/javascript" src="../libraries/RGraph.common.tooltips.js" ></script>
    <script type="text/javascript" src="../libraries/RGraph.bar.js" ></script>
    <!--[if lt IE 9]><script src="../excanvas/excanvas.js"></script><![endif]-->
    
    <title>A clickable grouped Bar chart</title>
    
    <meta name="description" content="A Bar chart that can be adjusted by clicking it" />
</head>
<body>

    <h1>A grouped Bar chart</h1>
    
    <p>
        
    </p>

    <canvas id="cvs" width="600" height="250">[No canvas support]</canvas>

    <br /><input type="text" id="out"/>

    <script>
        window.onload = function ()
        {
            var bar5 = new RGraph.Bar('cvs', [[45,60],[65,30],[40,80],[115,100]])
                .Set('colors', ['#CC1111', '#11CCCC', '#1111CC'])
                .Set('labels', ['Bob', 'Jamie', 'Cynthia', 'Peter'])
                .Set('strokestyle', 'transparent')
                .Set('ymax', 150)
                .Draw();

            
            bar5.canvas.onmousedown = function (e)
            {
                var obj   = e.target.__object__;
                var value = obj.getValue(e);
                var shape = obj.getShapeByX(e);

                if (shape && value) {
                        value = Number(parseFloat(value).toFixed(1));
                    var index = shape['index'];
                    var group = RGraph.sequentialIndexToGrouped(index, obj.data);
    
                    obj.data[group[0]][group[1]] = value.toFixed(1);
                    
                    document.getElementById("out").value = "Value: " + value;
                    console.log('Value is: ' + value);
                }
            }
        }
    </script>

    <p>
        <a href="./">&laquo; Back</a>
    </p>

</body>
</html>